
s = "abc"
for c in s:
    print(c)

"""
for i in 123:
    print(i) #TypeError: 'int' object is not iterable
"""

"""
['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', 
'__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', 
'__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', 
'__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', 
'__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', 
'__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', 
'__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__',
 '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 
 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes']

# 查看对象中的方法和函数, 里面没有__iter__, 说明是不可迭代对象
print(dir(123))
"""

"""
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__',
 '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', 
 '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', 
 '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
 '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 
 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find',
  'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 
  'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 
  'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 
  'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 
  'swapcase', 'title', 'translate', 'upper', 'zfill']

# 查看对象中的方法和函数, 里面有__iter__, 说明是可迭代对象
print(dir(s))
"""

"""也可以通过isinstence()查看对象是否可迭代
如果对象中有__iter__函数. 那么我们认为这个对象遵守了可迭代协议, 就可以获取到相应的迭代器

Iterable: 可迭代对象. 内部包含__iter__()5.函数
Iterator: 迭代器. 内部包含__iter__() 同时包含__next__().

迭代器的特点: 
 1. 节省内存.
 2. 惰性机制
 3. 不能反复, 只能向下执⾏.

from collections import Iterable
from collections import Iterator
l = [1, 2, 3]
l_iter = l.__iter__()
print(isinstance(l, Iterable)) # True
print(isinstance(l, Iterator)) # False
print(isinstance(l_iter, Iterator)) # True
print(isinstance(l_iter, Iterable)) # True
"""


"""
iter()和next()

1.可以通过iter()函数获取这些可迭代对象的迭代器
2.迭代器不断使用next()函数来获取下一条数据

"""
lst = [11, 22, 33]
lst_iter = iter(lst)
print(lst_iter)

print(next(lst_iter))
print(next(lst_iter))
print(next(lst_iter))

















